package com.ego.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ego.pojo.Brand;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author Ares
 */
public interface BrandMapper extends BaseMapper<Brand> {

    /**
     * 通过品牌ID删除种类和品牌的中间表
     * @param id 品牌ID
     * @return 返回受影响的行
     */
    @Delete("delete from tb_category_brand where brand_id=#{id}")
    Integer deleteCategoryBrand(Long id);

    /**
     * 通过种类ID和品牌ID插入数据到种类和品牌的中间表
     * @param cid 种类ID
     * @param id 品牌ID
     * @return 返回受影响的行
     */
    @Insert("insert into tb_category_brand (category_id, brand_id) values (#{cid},#{id})")
    Integer insertCategoryBrand(Long cid, Long id);

    /**
     * 通过种类ID查询到品牌的集合
     * @param cid 种类ID
     * @return 返回品牌集合
     */
    @Select("select * from tb_brand where id in (select brand_id from tb_category_brand where category_id=#{cid})")
    List<Brand> selectListByCid(Long cid);

}
